package com.u.social.multimedia.controller;

import com.u.social.multimedia.model.VideoMeta;
import com.u.social.multimedia.service.IVideoService;
import org.springframework.core.io.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: u-social
 * @description: 视频控制器类
 * @author: Alex Wu
 * @createDate: 2025-03-14 11:34
 **/

@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private IVideoService videoService;


    @PostMapping("/submit")
   public Boolean submitVideo(@RequestParam("video") MultipartFile file, @RequestBody VideoMeta meta) {
        // 此其实不用上传，直接用存储URL上传即可
        return videoService.submitVideo(file, meta);
    }


    // 获取当前播放数视频的 .mpd 播放列表文件，里面包含多个视频片段的播放地址
    @GetMapping("/play/{videoId}/mainfest.mpd")
    public ResponseEntity<Resource> getVideoManifest(@PathVariable String videoId) {
        return videoService.getVideoManifest(videoId);
    }

    @GetMapping("/play/{videoId}/{segmentId}")
    public ResponseEntity<Resource> getVideoSegment(@PathVariable String videoId, @PathVariable String segmentId) {
        return videoService.getVideoSegment(videoId, segmentId);
    }


}
